package edu.vt.ece.rt.benchmark.rbtree;

import java.util.Random;

import edu.vt.ece.rt.quorum.util.AbortException;


public class Benchmark extends edu.vt.ece.rt.benchmark.Benchmark{

		Random r = new Random();
		
		@Override
		protected void createLocalObjects() {

			try {
				// should be power of 2 - 2 !!!!
				RBTree.createBtree(0, localObjectsCount);
				
				
			} catch (Throwable e) {
				e.printStackTrace();
			}
		}

		@Override
		protected Object randomId() {
			return null;
		}
		
		
		@Override
		protected int getOperandsCount() {
			return 0;
		}

		@Override
		protected void readOperation(Object... ids) {
			
			int val = r.nextInt(localObjectsCount);
			if (RBTree.find(val, null)) {

			}
//			RBTree.testRotate(val, null);
		}

		@Override
		protected void writeOperation(Object... ids) {

//			try {
				RBTree.write(localObjectsCount, nesting);
//				float val = -0.25f;
//				RBTree.add(val, null);
//				System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is "+RBTree.find(val, null));
//				val = -0.5f;
//				RBTree.add(val, null);
//				System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is "+RBTree.find(val, null));
//				val = 5.5f;
//				RBTree.add(val, null);
//				System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is "+RBTree.find(val, null));

				
//				RBTree.add(-0.5f, null);
//				RBTree.add(5.5f, null);
//				RBTree.add(7, null);
//				RBTree.add(8, null);
//				RBTree.find(0, null);
//				RBTree.find(5.5f, null);
//				RBTree.add(-0.5f, null);
//				RBTree.add(-0.25f, null);
//				RBTree.find(0, null);
//				Random r = new Random();
//				int val = r.nextInt(2*localObjectsCount);
//////				int val = 8;
//				if (r.nextInt(100) < 50) {
//					RBTree.add(val, null);
//					if (RBTree.find(val, null))
//						System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is correct");
//					else
//						System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is WTF");
//				} else {
//					RBTree.delete(val, null);
//					if (!RBTree.find(val, null))
//						System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is correct");
//					else
//						System.out.println("Find for ----------------------------------------------------------------------------------------- "+val+" is WTF");
//
//				}	
				
////				val = 9;
////				RBTree.delete(val, null);
////				System.out.println("Find for "+val+" is "+RBTree.find(val, null));
////				val = 3;
////				RBTree.delete(val, null);
////				System.out.println("Find for "+val+" is "+RBTree.find(val, null));
//
////				val = 4;
////				System.out.println("Find for "+val+" is "+RBTree.find(val, null));

//			} catch (AbortException e) {
//				e.printStackTrace();
//			}
			
		}

		@Override
		protected void checkSanity() {
			return;
		}


		@Override
		protected String getLabel() {
			return "rbtree-qr";
		}

}
